//
// Created by lxinp on 2022/8/9.
//

#include <iostream>
#include "stack.h"
#include "assert.h"


template<typename T>
Stack<T>::Stack() : top(nullptr) {}


template<typename T>
bool Stack<T>::is_empty() {
    return !top;
}


template<typename T>
void Stack<T>::push(T elt) {
    Node* curr = new Node(elt, top);
    top = curr;
}


template<typename T>
void Stack<T>::pop() {
    assert(!is_empty());
    Node* temp = top;
    top = top->next;
    delete temp;
}


template<typename T>
T Stack<T>::get_top() {
    return top->elt;
}


template<typename T>
void Stack<T>::print() {
    std::cout << "[ ";
    Node* curr = top;
    while (curr) {
        std::cout << curr->elt << " | ";
        curr = curr->next;
    }
    std::cout << "<-top" << std::endl;
}


template<typename T>
Stack<T>::~Stack() {
    while (top) pop();
}


template class Stack<int>;
